package VistaConexion;

import metodos.Prism;
import metodos.IndiceGini;
import metodos.K_means;
import metodos.OneRule;
import metodos.ID3;
import metodos.Asociacion;
import metodos.Metodo;
import datos.Datos;
import java.awt.Frame;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import metodos.Bayes;

public class main extends javax.swing.JFrame {

    Conexion conexion;
    ArrayList<Object> listaCampos;
    int intentos = 0; //contador temporal para pruebas.
    ArrayList<ArrayList<String>> lista;
    String[] nombreAtributos;
    Metodo metodo;
    int metodo_elegido;
    ArrayList<String> query_campos;
    private String reglasProlog;

    public main() {
        this.reglasProlog = "";
        initComponents();
        this.setLocationRelativeTo(null);
        this.metodo_elegido = 0;
        listaCampos = new ArrayList<Object>();
        lista = new ArrayList<ArrayList<String>>();
        query_campos = new ArrayList<String>();
        nombreAtributos = null;
        metodo = null;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
        desactivarBotones();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane7 = new javax.swing.JScrollPane();
        jPanel2 = new javax.swing.JPanel();
        lblStatus = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        lblUser = new javax.swing.JLabel();
        textUser = new javax.swing.JTextField();
        lblPassword = new javax.swing.JLabel();
        textPassword = new javax.swing.JPasswordField();
        btnConectar = new javax.swing.JButton();
        btnDisconnect = new javax.swing.JButton();
        jComboBoxBD = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        cmbDatabases = new javax.swing.JComboBox();
        btnLoadTables = new javax.swing.JButton();
        btnCambiarBD = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        cmbTablas = new javax.swing.JComboBox();
        btnGenerar = new javax.swing.JButton();
        jPanelMetodos = new javax.swing.JPanel();
        jButtonPrism = new javax.swing.JButton();
        jButtonOneRule = new javax.swing.JButton();
        jButtonIndiceGini = new javax.swing.JButton();
        jButtonID3 = new javax.swing.JButton();
        jButtonAsociacion = new javax.swing.JButton();
        jButtonBayes = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        btnQuitar = new javax.swing.JButton();
        btnAgregar = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        listSeleccion = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        listGeneral = new javax.swing.JList();
        jButtonMostrarDatos = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        cmbSalida = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        textTablas = new javax.swing.JTextPane();
        btnCalcular = new javax.swing.JButton();
        jButtonGeneraProlog = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        presicionTF = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Proyecto Inteligencia Artificial");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setMinimumSize(new java.awt.Dimension(670, 600));
        setName("formPrincipal"); // NOI18N

        lblStatus.setText("Listo.");

        lblUser.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblUser.setText("Usuario:");

        textUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textUserActionPerformed(evt);
            }
        });
        textUser.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                textUserKeyPressed(evt);
            }
        });

        lblPassword.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblPassword.setLabelFor(textPassword);
        lblPassword.setText("Contraseña:");

        textPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textPasswordActionPerformed(evt);
            }
        });
        textPassword.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                textPasswordKeyPressed(evt);
            }
        });

        btnConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/conexion_bd.png"))); // NOI18N
        btnConectar.setToolTipText("Conectar a la Base de Datos");
        btnConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConectarActionPerformed(evt);
            }
        });

        btnDisconnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/delete_campo.png"))); // NOI18N
        btnDisconnect.setToolTipText("Desconectar del servidor");
        btnDisconnect.setEnabled(false);
        btnDisconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDisconnectActionPerformed(evt);
            }
        });

        jComboBoxBD.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MySQL", "Oracle", "Postgres", "SQL Server" }));

        jLabel1.setText("Servidor");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jComboBoxBD, 0, 140, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(34, 34, 34)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(lblUser)
                        .addGap(81, 81, 81)
                        .addComponent(lblPassword))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(textUser, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(13, 13, 13)
                        .addComponent(textPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnConectar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnDisconnect, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblUser)
                        .addComponent(jLabel1))
                    .addComponent(lblPassword))
                .addGap(2, 2, 2)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(textUser, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(textPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnDisconnect, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnConectar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jLabel3.setText("Base de datos");

        cmbDatabases.setEnabled(false);

        btnLoadTables.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/1348811236_accept-database.png"))); // NOI18N
        btnLoadTables.setToolTipText("Conectar Base de datos");
        btnLoadTables.setEnabled(false);
        btnLoadTables.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoadTablesActionPerformed(evt);
            }
        });

        btnCambiarBD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/desconectar_bd.png"))); // NOI18N
        btnCambiarBD.setToolTipText("Desconectar base de datos");
        btnCambiarBD.setEnabled(false);
        btnCambiarBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCambiarBDActionPerformed(evt);
            }
        });

        jLabel5.setText("Tablas");

        cmbTablas.setEnabled(false);
        cmbTablas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTablasActionPerformed(evt);
            }
        });

        btnGenerar.setText("Vista minable");
        btnGenerar.setEnabled(false);
        btnGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLoadTables, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCambiarBD, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(cmbDatabases, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(cmbTablas, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(btnGenerar, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(btnLoadTables, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(btnCambiarBD)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbDatabases, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel5)
                        .addGap(8, 8, 8)
                        .addComponent(cmbTablas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnGenerar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelMetodos.setBorder(javax.swing.BorderFactory.createTitledBorder("Metodos"));

        jButtonPrism.setText("Prism");
        jButtonPrism.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/select.png"))); // NOI18N
        jButtonPrism.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPrismActionPerformed(evt);
            }
        });

        jButtonOneRule.setText("One Rule");
        jButtonOneRule.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/select.png"))); // NOI18N
        jButtonOneRule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOneRuleActionPerformed(evt);
            }
        });

        jButtonIndiceGini.setText("Indice Gini");
        jButtonIndiceGini.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/select.png"))); // NOI18N
        jButtonIndiceGini.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIndiceGiniActionPerformed(evt);
            }
        });

        jButtonID3.setText("ID3");
        jButtonID3.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/select.png"))); // NOI18N
        jButtonID3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonID3ActionPerformed(evt);
            }
        });

        jButtonAsociacion.setText("Asociacion");
        jButtonAsociacion.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/select.png"))); // NOI18N
        jButtonAsociacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAsociacionActionPerformed(evt);
            }
        });

        jButtonBayes.setText("Bayes");
        jButtonBayes.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/select.png"))); // NOI18N
        jButtonBayes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBayesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelMetodosLayout = new javax.swing.GroupLayout(jPanelMetodos);
        jPanelMetodos.setLayout(jPanelMetodosLayout);
        jPanelMetodosLayout.setHorizontalGroup(
            jPanelMetodosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMetodosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelMetodosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButtonBayes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonIndiceGini, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                    .addComponent(jButtonOneRule, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonAsociacion, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                    .addComponent(jButtonPrism, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonID3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jPanelMetodosLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonAsociacion, jButtonID3, jButtonIndiceGini, jButtonOneRule, jButtonPrism});

        jPanelMetodosLayout.setVerticalGroup(
            jPanelMetodosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMetodosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonOneRule)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonIndiceGini)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonAsociacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonID3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonPrism)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonBayes)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnQuitar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/delete_campo.png"))); // NOI18N
        btnQuitar.setToolTipText("Eliminar Campo");
        btnQuitar.setEnabled(false);
        btnQuitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuitarActionPerformed(evt);
            }
        });

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/add_campo.png"))); // NOI18N
        btnAgregar.setToolTipText("Agregar Campo");
        btnAgregar.setEnabled(false);
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        listSeleccion.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(listSeleccion);

        listGeneral.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listGeneral.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                listGeneralMouseDragged(evt);
            }
        });
        jScrollPane1.setViewportView(listGeneral);

        jButtonMostrarDatos.setText("Mostrar Datos");
        jButtonMostrarDatos.setEnabled(false);
        jButtonMostrarDatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMostrarDatosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(btnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonMostrarDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(44, 44, 44))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane1, jScrollPane3});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addComponent(jScrollPane1))
                .addGap(8, 8, 8)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAgregar)
                    .addComponent(btnQuitar)
                    .addComponent(jButtonMostrarDatos))
                .addContainerGap())
        );

        jLabel4.setText("Seleccione la Clase:");

        cmbSalida.setEnabled(false);
        cmbSalida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbSalidaActionPerformed(evt);
            }
        });

        textTablas.setEditable(false);
        jScrollPane2.setViewportView(textTablas);

        btnCalcular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Seminario iconos/ejecutar.png"))); // NOI18N
        btnCalcular.setToolTipText("calcular");
        btnCalcular.setEnabled(false);
        btnCalcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCalcularActionPerformed(evt);
            }
        });

        jButtonGeneraProlog.setText("Generar Archivo Prolog");
        jButtonGeneraProlog.setEnabled(false);
        jButtonGeneraProlog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGeneraPrologActionPerformed(evt);
            }
        });

        jLabel2.setText("Presición");

        presicionTF.setText("100");
        presicionTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                presicionTFActionPerformed(evt);
            }
        });

        jLabel6.setForeground(new java.awt.Color(153, 153, 153));
        jLabel6.setText("ingrese un entero entre 1 y 100");

        jScrollPane5.setViewportView(jList2);

        jLabel7.setText("mostrar reglas que resulten en: (si no selecciona ninguno se mostraran todos)");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(cmbSalida, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(presicionTF, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, Short.MAX_VALUE)
                                .addComponent(jButtonGeneraProlog, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCalcular, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7)
                                .addGap(250, 250, 250))))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7))
                .addGap(1, 1, 1)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cmbSalida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButtonGeneraProlog)
                                .addComponent(jLabel2)
                                .addComponent(presicionTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6))
                            .addComponent(btnCalcular, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(4, 4, 4)
                .addComponent(jPanelMetodos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(28, 28, 28))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(10, 10, 10))
                    .addComponent(jPanelMetodos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane7.setViewportView(jPanel2);

        getContentPane().add(jScrollPane7, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void agregarCampo(Object campo) {
        for (int i = 0; i < listaCampos.size(); i++) {
            if (listaCampos.get(i).equals(campo)) {
                return;
            }
        }

        listaCampos.add(campo);
        listSeleccion.setListData(listaCampos.toArray());
    }

    public void setDatabases(ArrayList lista) {
        cmbDatabases.removeAll();
        for (int i = 0; i < lista.size(); i++) {
            cmbDatabases.addItem(lista.get(i));
        }
    }

    private void setTables(ArrayList lista) {
        cmbTablas.setModel(new javax.swing.DefaultComboBoxModel(lista.toArray()));
    }

    private void setCampos(ArrayList<String> lista) {
        listGeneral.setListData(lista.toArray());
        String lis[] = new String[0];
        this.listaCampos.clear();
        listSeleccion.setListData(lis);
    }

    private void btnCambiarBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCambiarBDActionPerformed
        jButtonMostrarDatos.setEnabled(false);
        cmbDatabases.setEnabled(true);
        btnLoadTables.setEnabled(true);
        btnCambiarBD.setEnabled(false);
        cmbTablas.setEnabled(false);
        btnAgregar.setEnabled(false);
        btnGenerar.setEnabled(false);
        btnQuitar.setEnabled(false);
        cmbSalida.setEnabled(false);
        btnCalcular.setEnabled(false);
        jButtonGeneraProlog.setEnabled(false);

        listaCampos.clear();
        listSeleccion.setListData(listaCampos.toArray());
        listGeneral.setListData(listaCampos.toArray());
        cmbTablas.removeAllItems();
        desactivarBotones();
    }//GEN-LAST:event_btnCambiarBDActionPerformed

    private void btnLoadTablesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadTablesActionPerformed

        try {
            String DataBaseName = cmbDatabases.getSelectedItem().toString();
            conexion.setDB(DataBaseName);
            ArrayList tablas = conexion.getTables();
            setTables(tablas);
            cmbDatabases.setEnabled(false);
            btnLoadTables.setEnabled(false);
            btnCambiarBD.setEnabled(true);
            cmbTablas.setEnabled(true);
            btnAgregar.setEnabled(true);
            btnGenerar.setEnabled(true);
            btnQuitar.setEnabled(true);
            cmbTablasActionPerformed(evt);
            lblStatus.setText("Tablas cargadas correctamente.");
            ArrayList todosCampos = new ArrayList();
            for (int i = 0; i < tablas.size(); i++) {
                ArrayList campos = conexion.getFields(tablas.get(i).toString());
                for (int j = 0; j < campos.size(); j++) {
                    todosCampos.add(tablas.get(i).toString() + "." + campos.get(j).toString());
                }
            }
        } catch (ClassNotFoundException ex) {
            lblStatus.setText("Ha ocurrido un error mientras se cargaban las tablas.");
            System.out.println(ex.toString());
        }
    }//GEN-LAST:event_btnLoadTablesActionPerformed

    private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
        btnCambiarBDActionPerformed(evt);
        textUser.setEnabled(true);
        textPassword.setEnabled(true);
        btnConectar.setEnabled(true);
        btnLoadTables.setEnabled(false);
        cmbDatabases.setEnabled(false);
        btnDisconnect.setEnabled(false);
        jButtonMostrarDatos.setEnabled(false);
        jButtonGeneraProlog.setEnabled(false);
        textTablas.setText("");
        cmbDatabases.removeAllItems();
        desactivarBotones();
    }//GEN-LAST:event_btnDisconnectActionPerformed

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        if (cmbDatabases.isEnabled()) {
            cmbDatabases.setEnabled(false);
        }

        if (listGeneral.getSelectedIndex() == -1) {
            return;
        }
        Object o = /*
                 * cmbTablas.getSelectedItem().toString() + "." +
                 */ listGeneral.getSelectedValue();
        agregarCampo(o);
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void cmbTablasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTablasActionPerformed
        try {
            cmbSalida.removeAllItems();
            textTablas.setText("");
            btnCalcular.setEnabled(false);
            cmbSalida.setEnabled(false);
            ArrayList< String> campos = conexion.getFields(cmbTablas.getSelectedItem().toString());
            setCampos(campos);

        } catch (Exception ex) {
        }
    }//GEN-LAST:event_cmbTablasActionPerformed

    private void btnQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarActionPerformed
        int indice = listSeleccion.getSelectedIndex();
        System.out.println(indice);
        if (indice == -1) {
            return;
        }
        for (int i = 0; i < listaCampos.size(); i++) {
            if (listaCampos.get(i).equals(listSeleccion.getSelectedValue())) {
                listaCampos.remove(i);
                listSeleccion.setListData(listaCampos.toArray());
            }

        }
    }//GEN-LAST:event_btnQuitarActionPerformed

    private void btnConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConectarActionPerformed

        conectarBD();
    }//GEN-LAST:event_btnConectarActionPerformed

    private void conectarBD() {
        Parametros parametros = new Parametros();

        parametros.deducirMotor(jComboBoxBD.getSelectedIndex(),
                textUser.getText(),
                new String(textPassword.getPassword()));

        try {
            conexion = new Conexion(parametros.getUsuario());
            ArrayList DBList = conexion.getDatabases();

            //Si existen bases de datos activa las opciones.
            if (DBList.size() > 0) {
                setDatabases(DBList);
                btnLoadTables.setEnabled(true);
                cmbDatabases.setEnabled(true);
            }
            btnDisconnect.setEnabled(true);
            btnDisconnect.setEnabled(true);
            btnConectar.setEnabled(false);
            textUser.setEnabled(false);
            textPassword.setEnabled(false);

            lblStatus.setText("Listo.");
        } catch (SQLException ex) {
            lblStatus.setText("No se pudo conectar al motor de base de datos. Intento fallido #: " + ++intentos);
            return;
        }

        if (btnCambiarBD.isEnabled()) {
            btnCambiarBD.setEnabled(false);
            textUser.setEnabled(false);
            textPassword.setEnabled(false);
        }
    }

    private void btnGenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarActionPerformed

        jButtonGeneraProlog.setEnabled(false);
        if (listSeleccion.getModel().getSize() < 3) {
            lblStatus.setText("Debe seleccionar al menos tres campos.");
            return;
        }
        cmbSalida.removeAllItems();
        cmbSalida.addItem((Object) new String("Seleccione el atributo clase"));
        for (int i = 0; i < listaCampos.size(); i++) {
            cmbSalida.addItem(listaCampos.get(i));
        }
        btnCalcular.setEnabled(true);
        cmbSalida.setEnabled(true);
        jButtonMostrarDatos.setEnabled(true);
        jPanelMetodos.setEnabled(true);
        activarBotones();


    }//GEN-LAST:event_btnGenerarActionPerformed

    private void listGeneralMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listGeneralMouseDragged
        try {
            (new Thread()).sleep(200);
        } catch (InterruptedException ex) {
        }
        btnAgregarActionPerformed(null);
    }//GEN-LAST:event_listGeneralMouseDragged
    private void desactivarBotones() {
        jButtonAsociacion.setEnabled(false);
        jButtonOneRule.setEnabled(false);
        jButtonPrism.setEnabled(false);
        jButtonID3.setEnabled(false);
        jButtonIndiceGini.setEnabled(false);
        jButtonBayes.setEnabled(false);
    }

    private void activarBotones() {
        jButtonAsociacion.setEnabled(true);
        jButtonOneRule.setEnabled(true);
        jButtonPrism.setEnabled(true);
        jButtonID3.setEnabled(true);
        jButtonIndiceGini.setEnabled(true);
        jButtonBayes.setEnabled(true);
    }

    private void desactivarBotonesAlgoritmos(int metodo) {

        jButtonAsociacion.setSelected(false);
        jButtonOneRule.setSelected(false);
        jButtonPrism.setSelected(false);
        jButtonID3.setSelected(false);
        jButtonIndiceGini.setSelected(false);
        jButtonBayes.setSelected(false);
        switch (metodo) {
            case 0:
                jButtonOneRule.setSelected(true);
                break;
            case 1:
                jButtonPrism.setSelected(true);
                break;
            case 2:
                jButtonID3.setSelected(true);
                break;
            case 3:
                jButtonAsociacion.setSelected(true);
                break;
            case 4:
                jButtonBayes.setSelected(true);
                break;
            case 5:
                jButtonIndiceGini.setSelected(true);
                break;
        }
    }

    private void jButtonOneRuleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOneRuleActionPerformed
        this.metodo_elegido = 0;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
    }//GEN-LAST:event_jButtonOneRuleActionPerformed

    private void jButtonPrismActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPrismActionPerformed
        this.metodo_elegido = 1;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
    }//GEN-LAST:event_jButtonPrismActionPerformed

    private void jButtonID3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonID3ActionPerformed
        this.metodo_elegido = 2;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
    }//GEN-LAST:event_jButtonID3ActionPerformed

    private void jButtonAsociacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAsociacionActionPerformed
        this.metodo_elegido = 3;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
    }//GEN-LAST:event_jButtonAsociacionActionPerformed

    private void jButtonIndiceGiniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIndiceGiniActionPerformed
        this.metodo_elegido = 5;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
    }//GEN-LAST:event_jButtonIndiceGiniActionPerformed

    private void textPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textPasswordActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textPasswordActionPerformed

    private void jButtonMostrarDatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMostrarDatosActionPerformed
        Minar m = new Minar(conexion.getUser(), cmbDatabases.getSelectedItem().toString());

        m.addTabla(cmbTablas.getSelectedItem().toString());
        ArrayList<String> campos = new ArrayList<String>();
        for (int i = 0; i < listaCampos.size(); i++) {
            m.addCampo(listaCampos.get(i).toString()); //Agrega Campos
            campos.add(listaCampos.get(i).toString());
        }
        m.addCamposRelacional(listaCampos.get(0).toString());

        m.Desnormalizar();
        lista = m.getTablaDesnormalizada();        // TODO add your handling code here:
        System.out.println(lista);
        JDialogTableDatos jdialog = new JDialogTableDatos(new Frame(), true, lista, campos);
        jdialog.setVisible(true);
    }//GEN-LAST:event_jButtonMostrarDatosActionPerformed

    private void textUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textUserActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textUserActionPerformed

    private void textUserKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textUserKeyPressed
        if (evt.getKeyCode() == 10) {
            conectarBD();
        }
    }//GEN-LAST:event_textUserKeyPressed

    private void textPasswordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textPasswordKeyPressed
        if (evt.getKeyCode() == 10) {
            conectarBD();
        }
    }//GEN-LAST:event_textPasswordKeyPressed

    private void jButtonBayesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBayesActionPerformed
        this.metodo_elegido = 4;
        desactivarBotonesAlgoritmos(this.metodo_elegido);
    }//GEN-LAST:event_jButtonBayesActionPerformed

    private void presicionTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_presicionTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_presicionTFActionPerformed

    private void jButtonGeneraPrologActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGeneraPrologActionPerformed
        exportar();
    }//GEN-LAST:event_jButtonGeneraPrologActionPerformed

    private void btnCalcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalcularActionPerformed
       
        Minar m = new Minar(conexion.getUser(), cmbDatabases.getSelectedItem().toString());

        m.addTabla(cmbTablas.getSelectedItem().toString());

        for (int i = 0; i < listaCampos.size(); i++) {
            m.addCampo(listaCampos.get(i).toString()); //Agrega Campos
        }
        m.addCamposRelacional(listaCampos.get(0).toString());

        m.Desnormalizar();
        lista = m.getTablaDesnormalizada();

        nombreAtributos = new String[listaCampos.size()];
        for (int i = 0; i < nombreAtributos.length; i++) {
            nombreAtributos[i] = listaCampos.get(i).toString();
        }

        Datos datos = new Datos();
        datos.setNombreClase(cmbSalida.getSelectedItem().toString());
        datos.setLista(lista);
        datos.setTitulos(nombreAtributos);


        switch (this.metodo_elegido) {
            case 1: //Prism
                int presicion;

                try {
                    presicion = Integer.parseInt(presicionTF.getText());
                    if(presicion>100 || presicion<1){
                    presicion=100;
                    }
                } catch (Exception e) {
                    presicion = 100;
                }
 
                metodo = new Prism(datos,presicion, jList2.getSelectedValues());
                break;
            case 2: // ID3
                metodo = new ID3(datos);
                break;
            case 3://Asociacion
               // metodo = new Asociacion(datos);

                break;

            case 4:
                frameBayes fb = new frameBayes(datos);
                fb.setLocationRelativeTo(null);
                fb.setVisible(true);
                break;
            case 5://Gini
                metodo = new IndiceGini(datos);
                break;
            default: //One Rule
                metodo = new OneRule(datos);

        }

        if (this.metodo_elegido != 4) {
            metodo.Calcular();
            System.out.println("Reglas prolog");
            //System.err.println(metodo.LeerReglasProlog());
            this.reglasProlog = metodo.LeerReglasProlog();
            //Imprime las reglas.
            textTablas.setText("Estas son las reglas:\n" + metodo.LeerReglas());
            lblStatus.setText("Reglas generadas exitosamente.");
        }
        jButtonGeneraProlog.setEnabled(true);

    }//GEN-LAST:event_btnCalcularActionPerformed

    private void cmbSalidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbSalidaActionPerformed


        if (!cmbSalida.getSelectedItem().toString().equals("Seleccione el atributo clase")) {
            if (cmbSalida.getItemAt(0).equals((Object) new String("Seleccione el atributo clase"))) {
                cmbSalida.removeItemAt(0);
            }
            Minar m = new Minar(conexion.getUser(), cmbDatabases.getSelectedItem().toString());

            m.addTabla(cmbTablas.getSelectedItem().toString());

            for (int i = 0; i < listaCampos.size(); i++) {
                m.addCampo(listaCampos.get(i).toString()); //Agrega Campos
            }
            m.addCamposRelacional(listaCampos.get(0).toString());

            m.Desnormalizar();
            lista = m.getTablaDesnormalizada();

            nombreAtributos = new String[listaCampos.size()];
            for (int i = 0; i < nombreAtributos.length; i++) {
                nombreAtributos[i] = listaCampos.get(i).toString();
            }
            Datos datos = new Datos();
            datos.setNombreClase(cmbSalida.getSelectedItem().toString());
            datos.setLista(lista);
            datos.setTitulos(nombreAtributos);
            DefaultListModel model = new DefaultListModel();
            for (int i = 0; i < datos.getPosiblesValores().get(cmbSalida.getSelectedIndex()).size(); i++) {
                model.addElement((Object) datos.getPosiblesValores().get(cmbSalida.getSelectedIndex()).get(i));
            }
            jList2.setModel(model);
        }

    }//GEN-LAST:event_cmbSalidaActionPerformed

    private void exportar() {
        JFileChooser jf = new JFileChooser();
        jf.setMultiSelectionEnabled(false);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("pl", "pl");
        jf.setFileFilter(filter);

        int r = jf.showSaveDialog(jf);
        if (r == JFileChooser.APPROVE_OPTION) {
            try {
                File file = jf.getSelectedFile();
                String path = file.getAbsolutePath() + ".pl";
                FileWriter fichero = new FileWriter(new File(path));
                fichero.write(this.reglasProlog);
                fichero.close();
                JOptionPane.showMessageDialog(null, "El archivo se ha exportado exitosamente");
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(rootPane, "Ocurrio un error al guardar el archivo\n" + ex.toString());
            }
        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new main().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnCalcular;
    private javax.swing.JButton btnCambiarBD;
    private javax.swing.JButton btnConectar;
    private javax.swing.JButton btnDisconnect;
    private javax.swing.JButton btnGenerar;
    private javax.swing.JButton btnLoadTables;
    private javax.swing.JButton btnQuitar;
    private javax.swing.JComboBox cmbDatabases;
    private javax.swing.JComboBox cmbSalida;
    private javax.swing.JComboBox cmbTablas;
    private javax.swing.JButton jButtonAsociacion;
    private javax.swing.JButton jButtonBayes;
    private javax.swing.JButton jButtonGeneraProlog;
    private javax.swing.JButton jButtonID3;
    private javax.swing.JButton jButtonIndiceGini;
    private javax.swing.JButton jButtonMostrarDatos;
    private javax.swing.JButton jButtonOneRule;
    private javax.swing.JButton jButtonPrism;
    private javax.swing.JComboBox jComboBoxBD;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JList jList2;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanelMetodos;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JLabel lblUser;
    private javax.swing.JList listGeneral;
    private javax.swing.JList listSeleccion;
    private javax.swing.JTextField presicionTF;
    private javax.swing.JPasswordField textPassword;
    private javax.swing.JTextPane textTablas;
    private javax.swing.JTextField textUser;
    // End of variables declaration//GEN-END:variables
}
